package com.company.thread;

import java.util.concurrent.CountDownLatch;

/**
 * @description: 同步机制1:  CountDownLatch
 * @author: ruoan
 * @date: 2020/12/11 0:05
 */
public class CountDownLatchDemo {

    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(6);

        for (int i = 0; i < 5; i++) {

            new Thread(()->{
                countDownLatch.countDown();
            },String.valueOf(i)).start();
        }

        //主线程main阻塞等待
        countDownLatch.await();
        System.out.println(Thread.currentThread().getName()+"退出");
    }
}
